package org.dreamland.adapter.web

import jakarta.servlet.http.HttpServletRequest
import jakarta.servlet.http.HttpServletResponse
import org.dreamland.application.AuthenticationService
import org.dreamland.application.query.LoginRequest
import org.dreamland.common.ResponseEntity
import org.dreamland.infrastructure.security.AuthMethod
import org.springframework.web.bind.annotation.*

@RestController
@RequestMapping("/auth")
class AuthenticationController(
    private val authenticationService: AuthenticationService
) {

    @PostMapping("/login")
    fun login(
        httpRequest: HttpServletRequest,
        httpResponse: HttpServletResponse,
        @RequestBody loginRequest: LoginRequest,
    ): ResponseEntity<String> {
        val sessionId = authenticationService.login(loginRequest, httpRequest, httpResponse)
        return ResponseEntity(payload = sessionId)
    }

    @GetMapping("captcha")
    fun captchaBase64Code(httpRequest: HttpServletRequest): ResponseEntity<String> {
        val captchaBase64Code = authenticationService.captchaBase64Code(httpRequest)
        return ResponseEntity(payload = captchaBase64Code)
    }
}